package com.hd123.rumba.qt.def;

import java.util.ArrayList;

import com.hd123.rumba.exception.BusinessException;

public class SQLOrderList extends ArrayList {
  /**
   * 返回适用于order by的子句
   * 
   * @return
   */
  public String getSQLClause() throws BusinessException {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < size(); ++i) {
      if (i > 0)
        sb.append(", ");
      SQLOrder item = (SQLOrder) get(i);
      sb.append(item.getSQLExpression());
    }
    return sb.length() == 0 ? null : sb.toString();
  }

  public String debugInfo() {
    StringBuffer sb = new StringBuffer();
    sb.append(getClass().getName() + "\n");
    for (int i = 0; i < size(); ++i) {
      SQLOrder item = (SQLOrder) get(i);
      sb.append(i + ": " + item.debugInfo() + "\n");
    }
    return sb.toString();
  }

}
